public class sellTickets implements Runnable{
    private int ticketsNums = 20;
    @Override
    public void run() {
        while (ticketsNums>0)
        {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("第"+ticketsNums--+"张票卖给了"+Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        Thread people1 = new Thread(new sellTickets(),"张三");
        Thread people2 = new Thread(new sellTickets(),"李四");
        Thread niuniu = new Thread(new sellTickets(),"黄牛");
        people1.start();
        people2.start();
        niuniu.start();
    }
}
//此时多个线程就会出现并发问题，同一张票卖给了好几个人。